import Vue from 'vue';
import { validateDate, strToDate } from '@/utils';

function formatNumber(val) {
    return val === void (0) || val == 0 ? '0.00' : `${val / 100}`
}

let filters = {
    formatTotalamt(val) {
        return `${formatNumber(val)}元`
    },
    formatPrice(val) {
        return `￥${formatNumber(val)}`
    },
    formatRequire(val) {
        return val == 1;
    },
    formatPayFlag(val) {
        return val == 2 ? '支付成功' : '未支付'
    },
    formatDate(date1, date2) {
        let res = validateDate(date1, date2);
        return res;
    },
    formatTag(val) {
        switch (val) {
            case '0':
                return '未开始'
                break;
            case '1':
                return '进行中'
                break;
            case '2':
                return '报名结束'
                break;
            default:
                break;
        }
    },
    formatTagClass(val) {
        switch (val) {
            case '0':
                return 'yello'
                break;
            case '1':
                return 'red'
                break;
            case '2':
                return 'gray'
                break;
            default:
                break;
        }
    },
    formatTime(val) {
      if(!val) return '未设置'
        // console.log(strToDate(val))
        let date = new Date(strToDate(val));
        let y = date.getFullYear();
        let m = (date.getMonth() + 1) > 9 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`;
        let d = (date.getDate() > 9) ? date.getDate() : `0${date.getDate()}`

        return `${y}年${m}月${d}日`
    },
    formatLabel(label, value) {
        return value ? label : null
    }
}

Object.keys(filters).forEach((key) => {
    Vue.filter(key, filters[key])
})
